package com.books4sale.feed.atom;

import java.util.Date;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import org.restlet.data.MediaType;
import org.restlet.data.Reference;
import org.restlet.ext.atom.Content;
import org.restlet.ext.atom.Entry;
import org.restlet.ext.atom.Link;
import org.restlet.ext.atom.Person;
import org.restlet.ext.atom.Relation;
import org.restlet.ext.atom.Text;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

import com.books4sale.admin.dto.Book;
import com.books4sale.admin.dto.tools.PMF;
import com.books4sale.feed.atom.builder.AtomBuilder;

public class BooksAtomFeed extends ServerResource {

	@Get
	public MyFeed test() throws InterruptedException {
		
		MyFeed atomFeed = AtomBuilder.get().buildFeed();
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query q = pm.newQuery(Book.class);
		List<Book> results = (List<Book>) q.execute();
		for (Book book : results) {
			Entry entry = new Entry();
			entry = AtomBuilder.get().buildBookEntry(book);
			atomFeed.getEntries().add(entry);
		}
		
		return atomFeed;
	}
}
